"""
WebSocket消息序列化器
用于生成WebSocket API文档
"""
from rest_framework import serializers


class StreamStartRequestSerializer(serializers.Serializer):
    """开始流式输出请求"""
    type = serializers.CharField(default='start_stream', help_text="消息类型")
    message = serializers.CharField(help_text="用户消息内容")
    model = serializers.CharField(default='gpt-3.5-turbo', help_text="AI模型名称")
    role = serializers.CharField(default='user', help_text="用户角色")


class StreamStopRequestSerializer(serializers.Serializer):
    """停止流式输出请求"""
    type = serializers.CharField(default='stop_stream', help_text="消息类型")
    stream_id = serializers.UUIDField(help_text="流式会话ID")


class PingRequestSerializer(serializers.Serializer):
    """心跳请求"""
    type = serializers.CharField(default='ping', help_text="消息类型")


class StreamStartResponseSerializer(serializers.Serializer):
    """流式输出开始响应"""
    type = serializers.CharField(default='stream_start', help_text="消息类型")
    stream_id = serializers.UUIDField(help_text="流式会话ID")
    user_message_id = serializers.IntegerField(help_text="用户消息ID")


class StreamChunkResponseSerializer(serializers.Serializer):
    """流式输出块响应"""
    type = serializers.CharField(default='stream_chunk', help_text="消息类型")
    stream_id = serializers.UUIDField(help_text="流式会话ID")
    content = serializers.CharField(help_text="当前累积内容")
    tokens = serializers.IntegerField(help_text="当前Token数")
    is_final = serializers.BooleanField(help_text="是否为最终块")


class StreamCompleteResponseSerializer(serializers.Serializer):
    """流式输出完成响应"""
    type = serializers.CharField(default='stream_complete', help_text="消息类型")
    stream_id = serializers.UUIDField(help_text="流式会话ID")
    message_id = serializers.IntegerField(help_text="AI回复消息ID")
    total_tokens = serializers.IntegerField(help_text="总Token数")


class StreamErrorResponseSerializer(serializers.Serializer):
    """流式输出错误响应"""
    type = serializers.CharField(default='stream_error', help_text="消息类型")
    stream_id = serializers.UUIDField(help_text="流式会话ID", required=False)
    message = serializers.CharField(help_text="错误消息")


class StreamStoppedResponseSerializer(serializers.Serializer):
    """流式输出停止响应"""
    type = serializers.CharField(default='stream_stopped', help_text="消息类型")
    stream_id = serializers.UUIDField(help_text="流式会话ID")


class PongResponseSerializer(serializers.Serializer):
    """心跳响应"""
    type = serializers.CharField(default='pong', help_text="消息类型")


class ErrorResponseSerializer(serializers.Serializer):
    """通用错误响应"""
    type = serializers.CharField(default='error', help_text="消息类型")
    message = serializers.CharField(help_text="错误消息")